/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.abc.salesinventory.ui.newpackage;

import com.abc.salesinventory.report.CustomerDetailsReport;
import com.abc.salesinventory.report.ProductDetailsReport;
import com.abc.salesinventory.report.StockDetailsReport;
import com.abc.salesinventory.report.SupplierDetailsReport;
import com.abc.salesinventory.report.ProductBasedOnExpire;
import com.abc.salesinventory.report.UserReport;
import com.abc.salesinventory.report.CustomerWiseSalesReport;
import com.abc.salesinventory.report.SupplierWisePurchasedAnalysisReport;
import com.abc.salesinventory.report.StockValueAnalysisReport;
import com.abc.salesinventory.report.DailySalesReport;
import com.abc.salesinventory.report.MonthlySalesReport;
import com.abc.salesinventory.report.FastMovingItems;
import com.abc.salesinventory.report.SlowMovingItemsReport;
import com.abc.salesinventory.report.PurchasedReciept;
import com.abc.salesinventory.report.SalesInvoice;
import com.abc.salesinventory.service.newpackage.SecurityService;
import com.abc.salesinventory.service.newpackage.SecurityServiceImpl;
import com.abc.salesinventory.service.sms.SMSMessageEngine;
import javax.swing.JOptionPane;

/**
 *
 * @author Manuri
 */
public class MainScreen extends javax.swing.JFrame {

    private String userId;
    private SecurityService securityService = new SecurityServiceImpl();
    SMSMessageEngine engine = new SMSMessageEngine();

    /**
     * Creates new form MainScreen
     */
    public MainScreen(String userId) {
        initComponents();
        setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
        this.engine.init();
        this.engine.setjDesktopPane(jDesktopPane1);
        this.userId = userId;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jDesktopPane1 = new com.abc.salesinventory.ui.newpackage.CustomDesktopPane();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuFile = new javax.swing.JMenu();
        miChangePassword = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        miExit = new javax.swing.JMenuItem();
        menuCustomer = new javax.swing.JMenu();
        miAddCus = new javax.swing.JMenuItem();
        miSearchCus = new javax.swing.JMenuItem();
        menuSupplier = new javax.swing.JMenu();
        miAddSupp = new javax.swing.JMenuItem();
        miSearchSup = new javax.swing.JMenuItem();
        menuProduct = new javax.swing.JMenu();
        miAddNewPrduct = new javax.swing.JMenuItem();
        miSearchProduct = new javax.swing.JMenuItem();
        menuStock = new javax.swing.JMenu();
        miReOrderProduct = new javax.swing.JMenuItem();
        miSearchStock = new javax.swing.JMenuItem();
        menuSales = new javax.swing.JMenu();
        miSales = new javax.swing.JMenuItem();
        menuPurchases = new javax.swing.JMenu();
        miPurchase = new javax.swing.JMenuItem();
        menuReport = new javax.swing.JMenu();
        miCustomerReport = new javax.swing.JMenuItem();
        miSupplierReport = new javax.swing.JMenuItem();
        miProductReport = new javax.swing.JMenuItem();
        miStockReport = new javax.swing.JMenuItem();
        miUserReport = new javax.swing.JMenuItem();
        miExpiredReport = new javax.swing.JMenuItem();
        miSupWisePurchased = new javax.swing.JMenuItem();
        miCusWiseSales = new javax.swing.JMenuItem();
        miStockValueAnlysis = new javax.swing.JMenuItem();
        miSalesInvoices = new javax.swing.JMenuItem();
        miPurchasedReceipts = new javax.swing.JMenuItem();
        miDailySalesReport = new javax.swing.JMenuItem();
        miMonthlySalesReport = new javax.swing.JMenuItem();
        miSlow = new javax.swing.JMenuItem();
        miFast = new javax.swing.JMenuItem();
        menuAccount = new javax.swing.JMenu();
        miCreateAcc = new javax.swing.JMenuItem();
        miSearchUser = new javax.swing.JMenuItem();
        menuUserRole = new javax.swing.JMenu();
        miChangeRole = new javax.swing.JMenuItem();
        miEditRole = new javax.swing.JMenuItem();
        menuMessage = new javax.swing.JMenu();
        miViewMessages = new javax.swing.JMenuItem();
        miMessageReOrderProduct = new javax.swing.JMenuItem();
        miCreateMessage = new javax.swing.JMenuItem();

        jMenu1.setText("jMenu1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sales & Inventory Management System - Eraj Pharmaceuticals");
        setExtendedState(1);

        jButton1.setText("Logout");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap(555, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(22, 22, 22))
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(522, Short.MAX_VALUE))
        );
        jDesktopPane1.setLayer(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        menuFile.setText("File");

        miChangePassword.setText("Change Password");
        miChangePassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miChangePasswordActionPerformed(evt);
            }
        });
        menuFile.add(miChangePassword);

        jMenuItem1.setText("Preferences");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menuFile.add(jMenuItem1);

        miExit.setText("Exit");
        miExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExitActionPerformed(evt);
            }
        });
        menuFile.add(miExit);

        jMenuBar1.add(menuFile);

        menuCustomer.setText("Customer");

        miAddCus.setText("Add Customer");
        miAddCus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAddCusActionPerformed(evt);
            }
        });
        menuCustomer.add(miAddCus);

        miSearchCus.setText("Search Customer");
        miSearchCus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSearchCusActionPerformed(evt);
            }
        });
        menuCustomer.add(miSearchCus);

        jMenuBar1.add(menuCustomer);

        menuSupplier.setText("Supplier");

        miAddSupp.setText("Add Supplier");
        miAddSupp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAddSuppActionPerformed(evt);
            }
        });
        menuSupplier.add(miAddSupp);

        miSearchSup.setText("Search Supplier");
        miSearchSup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSearchSupActionPerformed(evt);
            }
        });
        menuSupplier.add(miSearchSup);

        jMenuBar1.add(menuSupplier);

        menuProduct.setText("Product");

        miAddNewPrduct.setText("Create New Product");
        miAddNewPrduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAddNewPrductActionPerformed(evt);
            }
        });
        menuProduct.add(miAddNewPrduct);

        miSearchProduct.setText("Search Product");
        miSearchProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSearchProductActionPerformed(evt);
            }
        });
        menuProduct.add(miSearchProduct);

        jMenuBar1.add(menuProduct);

        menuStock.setText("Stock");

        miReOrderProduct.setText("Re-order Product List");
        miReOrderProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miReOrderProductActionPerformed(evt);
            }
        });
        menuStock.add(miReOrderProduct);

        miSearchStock.setText("Search Stock");
        miSearchStock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSearchStockActionPerformed(evt);
            }
        });
        menuStock.add(miSearchStock);

        jMenuBar1.add(menuStock);

        menuSales.setText("Sales");

        miSales.setText("Create Sales");
        miSales.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSalesActionPerformed(evt);
            }
        });
        menuSales.add(miSales);

        jMenuBar1.add(menuSales);

        menuPurchases.setText("Purchases");

        miPurchase.setText("Create Purchase");
        miPurchase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miPurchaseActionPerformed(evt);
            }
        });
        menuPurchases.add(miPurchase);

        jMenuBar1.add(menuPurchases);

        menuReport.setText("Reports");

        miCustomerReport.setText("Customer Details Report");
        miCustomerReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCustomerReportActionPerformed(evt);
            }
        });
        menuReport.add(miCustomerReport);

        miSupplierReport.setText("Supplier Details Report");
        miSupplierReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSupplierReportActionPerformed(evt);
            }
        });
        menuReport.add(miSupplierReport);

        miProductReport.setText("Product Details Report");
        miProductReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miProductReportActionPerformed(evt);
            }
        });
        menuReport.add(miProductReport);

        miStockReport.setText("Stock Details Report");
        miStockReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miStockReportActionPerformed(evt);
            }
        });
        menuReport.add(miStockReport);

        miUserReport.setText("User Report");
        miUserReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miUserReportActionPerformed(evt);
            }
        });
        menuReport.add(miUserReport);

        miExpiredReport.setText("Expired Products Detail Report");
        miExpiredReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExpiredReportActionPerformed(evt);
            }
        });
        menuReport.add(miExpiredReport);

        miSupWisePurchased.setText("Supplier Wise Purchased Report");
        miSupWisePurchased.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSupWisePurchasedActionPerformed(evt);
            }
        });
        menuReport.add(miSupWisePurchased);

        miCusWiseSales.setText("Customer Wise Sales Report");
        miCusWiseSales.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCusWiseSalesActionPerformed(evt);
            }
        });
        menuReport.add(miCusWiseSales);

        miStockValueAnlysis.setText("Stock Value Analysis Report");
        miStockValueAnlysis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miStockValueAnlysisActionPerformed(evt);
            }
        });
        menuReport.add(miStockValueAnlysis);

        miSalesInvoices.setText("Sales Invoices");
        miSalesInvoices.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSalesInvoicesActionPerformed(evt);
            }
        });
        menuReport.add(miSalesInvoices);

        miPurchasedReceipts.setText("Purchased Receipts");
        miPurchasedReceipts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miPurchasedReceiptsActionPerformed(evt);
            }
        });
        menuReport.add(miPurchasedReceipts);

        miDailySalesReport.setText("Daily Sales Report");
        miDailySalesReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miDailySalesReportActionPerformed(evt);
            }
        });
        menuReport.add(miDailySalesReport);

        miMonthlySalesReport.setText("Monthly Sales Report");
        miMonthlySalesReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miMonthlySalesReportActionPerformed(evt);
            }
        });
        menuReport.add(miMonthlySalesReport);

        miSlow.setText("Slow Moving Items");
        miSlow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSlowActionPerformed(evt);
            }
        });
        menuReport.add(miSlow);

        miFast.setText("Fast Moving Items");
        miFast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miFastActionPerformed(evt);
            }
        });
        menuReport.add(miFast);

        jMenuBar1.add(menuReport);

        menuAccount.setText("Account");

        miCreateAcc.setText("Create User Account");
        miCreateAcc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCreateAccActionPerformed(evt);
            }
        });
        menuAccount.add(miCreateAcc);

        miSearchUser.setText("Search User");
        miSearchUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSearchUserActionPerformed(evt);
            }
        });
        menuAccount.add(miSearchUser);

        jMenuBar1.add(menuAccount);

        menuUserRole.setText("User Role");

        miChangeRole.setText("Create User Role");
        miChangeRole.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miChangeRoleActionPerformed(evt);
            }
        });
        menuUserRole.add(miChangeRole);

        miEditRole.setText("Edit User Role");
        miEditRole.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miEditRoleActionPerformed(evt);
            }
        });
        menuUserRole.add(miEditRole);

        jMenuBar1.add(menuUserRole);

        menuMessage.setText("Message");

        miViewMessages.setText("View Messages");
        miViewMessages.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miViewMessagesActionPerformed(evt);
            }
        });
        menuMessage.add(miViewMessages);

        miMessageReOrderProduct.setText("Re-Order Products");
        miMessageReOrderProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miMessageReOrderProductActionPerformed(evt);
            }
        });
        menuMessage.add(miMessageReOrderProduct);

        miCreateMessage.setText("Create New Message");
        miCreateMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCreateMessageActionPerformed(evt);
            }
        });
        menuMessage.add(miCreateMessage);

        jMenuBar1.add(menuMessage);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miAddCusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddCusActionPerformed
        if (securityService.hasPermission("MANAGE_CUSTOMERS", this.userId)) {
            jDesktopPane1.add(new CreateCustomer()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miAddCusActionPerformed

    private void miSearchCusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSearchCusActionPerformed
        if (securityService.hasPermission("MANAGE_CUSTOMERS", this.userId)) {
            SearchCustomer sc = new SearchCustomer();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSearchCusActionPerformed

    private void miAddSuppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddSuppActionPerformed
        if (securityService.hasPermission("MANAGE_SUPPLIERS", this.userId)) {
            jDesktopPane1.add(new CreateSupplier()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miAddSuppActionPerformed

    private void miSearchSupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSearchSupActionPerformed
        if (securityService.hasPermission("MANAGE_SUPPLIERS", this.userId)) {
            SearchSupplier ss = new SearchSupplier();
            ss.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(ss).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSearchSupActionPerformed

    private void miSalesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSalesActionPerformed
        if (securityService.hasPermission("DO_SALES", this.userId)) {
            Sales ss = new Sales(engine);
            ss.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(ss).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSalesActionPerformed

    private void miPurchaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miPurchaseActionPerformed
        if (securityService.hasPermission("DO_PURCHASES", this.userId)) {
            Purchases ss = new Purchases();
            ss.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(ss).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miPurchaseActionPerformed

    private void miCreateAccActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCreateAccActionPerformed
        if (securityService.hasPermission("MANAGE_USERS", this.userId)) {
            jDesktopPane1.add(new CreateUser()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miCreateAccActionPerformed

    private void miSearchUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSearchUserActionPerformed
        if (securityService.hasPermission("MANAGE_USERS", this.userId)) {
            SearchUser su = new SearchUser();
            su.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(su).setVisible(true);

        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSearchUserActionPerformed

    private void miChangeRoleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miChangeRoleActionPerformed
        if (securityService.hasPermission("MANAGE_ROLES", this.userId)) {
            jDesktopPane1.add(new CreateRole()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miChangeRoleActionPerformed

    private void miEditRoleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miEditRoleActionPerformed
        if (securityService.hasPermission("MANAGE_ROLES", this.userId)) {
            jDesktopPane1.add(new EditUserRole()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miEditRoleActionPerformed

    private void miChangePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miChangePasswordActionPerformed
        jDesktopPane1.add(new ChangePassword(this.userId)).setVisible(true);
    }//GEN-LAST:event_miChangePasswordActionPerformed

    private void miExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExitActionPerformed
        int dialogButton = JOptionPane.YES_NO_OPTION;
        int dialogResult = JOptionPane.showConfirmDialog(null, "Would You Like to Exit?", "Warning", dialogButton);
        if (dialogResult == JOptionPane.YES_OPTION) {
            System.exit(0);
        }


    }//GEN-LAST:event_miExitActionPerformed

    private void miSupplierReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSupplierReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            SupplierDetailsReport sc = new SupplierDetailsReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSupplierReportActionPerformed

    private void miProductReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miProductReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            ProductDetailsReport sc = new ProductDetailsReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miProductReportActionPerformed

    private void miExpiredReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExpiredReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            ProductBasedOnExpire sc = new ProductBasedOnExpire();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miExpiredReportActionPerformed

    private void miStockValueAnlysisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miStockValueAnlysisActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            StockValueAnalysisReport sc = new StockValueAnalysisReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miStockValueAnlysisActionPerformed

    private void miSlowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSlowActionPerformed
        //if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
        SlowMovingItemsReport sc = new SlowMovingItemsReport();
//        sc.setjDesktopPane(jDesktopPane1);
        jDesktopPane1.add(sc).setVisible(true);
        // }else {
        // JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        // }
    }//GEN-LAST:event_miSlowActionPerformed

    private void miCustomerReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCustomerReportActionPerformed
        // if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
        CustomerDetailsReport sc = new CustomerDetailsReport();
        sc.setjDesktopPane(jDesktopPane1);
        jDesktopPane1.add(sc).setVisible(true);
        // }else {
        //     JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        // }
    }//GEN-LAST:event_miCustomerReportActionPerformed

    private void miStockReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miStockReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            StockDetailsReport sc = new StockDetailsReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miStockReportActionPerformed

    private void miSupWisePurchasedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSupWisePurchasedActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            SupplierWisePurchasedAnalysisReport sc = new SupplierWisePurchasedAnalysisReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSupWisePurchasedActionPerformed

    private void miCusWiseSalesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCusWiseSalesActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            CustomerWiseSalesReport sc = new CustomerWiseSalesReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miCusWiseSalesActionPerformed

    private void miDailySalesReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDailySalesReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            DailySalesReport sc = new DailySalesReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miDailySalesReportActionPerformed

    private void miMonthlySalesReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMonthlySalesReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            jDesktopPane1.add(new MonthlySalesReport()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miMonthlySalesReportActionPerformed

    private void miFastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miFastActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            jDesktopPane1.add(new FastMovingItems()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miFastActionPerformed

    private void miPurchasedReceiptsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miPurchasedReceiptsActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            PurchasedReciept sc = new PurchasedReciept();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miPurchasedReceiptsActionPerformed

    private void miSalesInvoicesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSalesInvoicesActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {

            SalesInvoice si = new SalesInvoice();
            si.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(si).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSalesInvoicesActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            jDesktopPane1.add(new Preferences()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void miUserReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miUserReportActionPerformed
        if (securityService.hasPermission("GENERATE_REPORTS", this.userId)) {
            UserReport sc = new UserReport();
            sc.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(sc).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }

    }//GEN-LAST:event_miUserReportActionPerformed

    private void miSearchStockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSearchStockActionPerformed
        if (securityService.hasPermission("DO_PURCHASES", this.userId)) {
            jDesktopPane1.add(new SearchStock()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSearchStockActionPerformed

    private void miReOrderProductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miReOrderProductActionPerformed
        if (securityService.hasPermission("DO_PURCHASES", this.userId)) {
            jDesktopPane1.add(new ReorederProducts()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miReOrderProductActionPerformed

    private void miViewMessagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miViewMessagesActionPerformed
        if (securityService.hasPermission("SEND_MESSAGES", this.userId)) {
            jDesktopPane1.add(new AllMessages()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miViewMessagesActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
        new Login().setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void miMessageReOrderProductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMessageReOrderProductActionPerformed
         if (securityService.hasPermission("SEND_MESSAGES", this.userId)) {
            jDesktopPane1.add(new AutomaticReorderPopup(engine)).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miMessageReOrderProductActionPerformed

    private void miAddNewPrductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddNewPrductActionPerformed
        if (securityService.hasPermission("MANAGE_PRODUCTS", this.userId)) {
            jDesktopPane1.add(new AddNewProduct()).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miAddNewPrductActionPerformed

    private void miSearchProductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSearchProductActionPerformed
        if (securityService.hasPermission("MANAGE_PRODUCTS", this.userId)) {
            SearchProduct su = new SearchProduct();
            su.setjDesktopPane(jDesktopPane1);
            jDesktopPane1.add(su).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miSearchProductActionPerformed

    private void miCreateMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCreateMessageActionPerformed
         if (securityService.hasPermission("SEND_MESSAGES", this.userId)) {
            jDesktopPane1.add(new CreateNewMessage(engine)).setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "You are not authorized to access this.", "No Access", 2);
        }
    }//GEN-LAST:event_miCreateMessageActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainScreen("abc").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private com.abc.salesinventory.ui.newpackage.CustomDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenu menuAccount;
    private javax.swing.JMenu menuCustomer;
    private javax.swing.JMenu menuFile;
    private javax.swing.JMenu menuMessage;
    private javax.swing.JMenu menuProduct;
    private javax.swing.JMenu menuPurchases;
    private javax.swing.JMenu menuReport;
    private javax.swing.JMenu menuSales;
    private javax.swing.JMenu menuStock;
    private javax.swing.JMenu menuSupplier;
    private javax.swing.JMenu menuUserRole;
    private javax.swing.JMenuItem miAddCus;
    private javax.swing.JMenuItem miAddNewPrduct;
    private javax.swing.JMenuItem miAddSupp;
    private javax.swing.JMenuItem miChangePassword;
    private javax.swing.JMenuItem miChangeRole;
    private javax.swing.JMenuItem miCreateAcc;
    private javax.swing.JMenuItem miCreateMessage;
    private javax.swing.JMenuItem miCusWiseSales;
    private javax.swing.JMenuItem miCustomerReport;
    private javax.swing.JMenuItem miDailySalesReport;
    private javax.swing.JMenuItem miEditRole;
    private javax.swing.JMenuItem miExit;
    private javax.swing.JMenuItem miExpiredReport;
    private javax.swing.JMenuItem miFast;
    private javax.swing.JMenuItem miMessageReOrderProduct;
    private javax.swing.JMenuItem miMonthlySalesReport;
    private javax.swing.JMenuItem miProductReport;
    private javax.swing.JMenuItem miPurchase;
    private javax.swing.JMenuItem miPurchasedReceipts;
    private javax.swing.JMenuItem miReOrderProduct;
    private javax.swing.JMenuItem miSales;
    private javax.swing.JMenuItem miSalesInvoices;
    private javax.swing.JMenuItem miSearchCus;
    private javax.swing.JMenuItem miSearchProduct;
    private javax.swing.JMenuItem miSearchStock;
    private javax.swing.JMenuItem miSearchSup;
    private javax.swing.JMenuItem miSearchUser;
    private javax.swing.JMenuItem miSlow;
    private javax.swing.JMenuItem miStockReport;
    private javax.swing.JMenuItem miStockValueAnlysis;
    private javax.swing.JMenuItem miSupWisePurchased;
    private javax.swing.JMenuItem miSupplierReport;
    private javax.swing.JMenuItem miUserReport;
    private javax.swing.JMenuItem miViewMessages;
    // End of variables declaration//GEN-END:variables
}
